package co.edu.udem.controller;

import java.io.IOException;
import java.security.InvalidAlgorithmParameterException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import co.edu.udem.service.GenericService;

/**
 * 
 */
@Controller
@RequestMapping("/Sync")
public class SyncController extends BaseController {

	@Autowired
	private GenericService placeService;

	@Autowired
	private GenericService subjectService;

	@Autowired
	private GenericService subjectDetailService;

	@Autowired
	private GenericService notificationService;

	@RequestMapping(value = "/place/list/{version}", method = RequestMethod.GET, headers = "Accept=text/*, application/json")
	public void getPlaceList(@PathVariable("version") String version,
			@RequestParam("usr") String userCode,
			@RequestParam("pwd") String password,
			@RequestParam("ut") String userType,
			@RequestParam("sid") String encryptedSessionId,
			@RequestParam("da") String dateAuthentication,
			HttpServletResponse servletResponse) throws IOException,
			InvalidKeyException, NoSuchAlgorithmException,
			IllegalBlockSizeException, NoSuchPaddingException,
			BadPaddingException, InvalidAlgorithmParameterException {

		consumeService(placeService, userCode, password, userType,
				encryptedSessionId, dateAuthentication, servletResponse);
	}

	@RequestMapping(value = "/subject/list/{version}", method = RequestMethod.GET, headers = "Accept=text/*, application/json")
	public void getSubjectList(@PathVariable("version") String version,
			@RequestParam("usr") String userCode,
			@RequestParam("pwd") String password,
			@RequestParam("ut") String userType,
			@RequestParam("sid") String encryptedSessionId,
			@RequestParam("da") String dateAuthentication,
			HttpServletResponse servletResponse) throws IOException,
			InvalidKeyException, NoSuchAlgorithmException,
			IllegalBlockSizeException, NoSuchPaddingException,
			BadPaddingException, InvalidAlgorithmParameterException {

		consumeService(subjectService, userCode, password, userType,
				encryptedSessionId, dateAuthentication, servletResponse,
				userCode, userType);
	}

	@RequestMapping(value = "/detail/list/{version}", method = RequestMethod.GET, headers = "Accept=text/*, application/json")
	public void getSubjectDetailList(@PathVariable("version") String version,
			@RequestParam("usr") String userCode,
			@RequestParam("pwd") String password,
			@RequestParam("ut") String userType,
			@RequestParam("sid") String encryptedSessionId,
			@RequestParam("da") String dateAuthentication,
			HttpServletResponse servletResponse) throws IOException,
			InvalidKeyException, NoSuchAlgorithmException,
			IllegalBlockSizeException, NoSuchPaddingException,
			BadPaddingException, InvalidAlgorithmParameterException {

		consumeService(subjectDetailService, userCode, password, userType,
				encryptedSessionId, dateAuthentication, servletResponse,
				userCode, userType);
	}

	@RequestMapping(value = "/notification/list/{version}", method = RequestMethod.GET, headers = "Accept=text/*, application/json")
	public void getNotificationList(@PathVariable("version") String version,
			@RequestParam("usr") String userCode,
			@RequestParam("pwd") String password,
			@RequestParam("ut") String userType,
			@RequestParam("sid") String encryptedSessionId,
			@RequestParam("da") String dateAuthentication,
			HttpServletResponse servletResponse) throws IOException,
			InvalidKeyException, NoSuchAlgorithmException,
			IllegalBlockSizeException, NoSuchPaddingException,
			BadPaddingException, InvalidAlgorithmParameterException {

		consumeService(notificationService, userCode, password, userType,
				encryptedSessionId, dateAuthentication, servletResponse,
				userCode, userType);
	}

}
